package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.bso.SysMenuBso;
import com.eric.service.ISysMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-12
 */
@RestController
@RequestMapping("/sys-menu")
@RequiredArgsConstructor
public class SysMenuController {
    private final ISysMenuService menuService;

//    新增加一条菜单数据
    @PostMapping("/saveOne")
    @SaCheckRole(value = {"sys:coder"},mode = SaMode.OR)
    public SaResult saveOne(SysMenuBso menuBso, MultipartFile icoPathFile, HttpServletRequest request){
        return menuService.saveOneService(menuBso,icoPathFile,request);
    }

//    递归获取所有菜单数据
    @GetMapping("/getAllMenus")
    public SaResult getAllMenus(){
        return menuService.getAllMenusService();
    }

//    通过父节点id获取菜单数据
    @GetMapping("/getChoseMenuList")
    public SaResult getChoseMenus(Integer pid,Integer level){
        return menuService.getChoseMenuListService(pid,level);
    }

//    获取所有菜单数据，但不显示分层结构
    @GetMapping("/getAllLine")
    public SaResult getAllLine(Integer current,Integer pageSize){
        return menuService.getAllLineService(current,pageSize);
    }
//   通过pid获取子菜单数据
    @GetMapping("/getChildren")
    public SaResult getChildren(Integer pid){
        return menuService.getChildrenService(pid);
    }

//    修改一条菜单数据
    @PutMapping("/modifyOne")
    @SaCheckPermission("sys:modify")
    @SaCheckRole(value = {"sys:coder"},mode = SaMode.OR)
    public SaResult modifyOne(SysMenuBso menuBso, MultipartFile icoPathFile, HttpServletRequest request){
        return menuService.modifyOneService(menuBso,icoPathFile,request);
    }
//    通过id删除一条菜单数据
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:delete")
    @SaCheckRole(value = {"sys:coder"},mode = SaMode.OR)
    public SaResult deleteOneById(@PathVariable("id") Integer id){
        return menuService.deleteOneByIdService(id);
    }

    @GetMapping("/getTreeMenuById")
    public SaResult getTreeMenuById(Integer id){
        return menuService.getTreeMenuByIdService(id);
    }

    /*
    * 一开始初始化一个用户时候，需要初始化该用户所在项目，所在仓库
    *
    *
    * */


    @GetMapping("/getBaseMenu")
    public SaResult getBaseMenu(){
        return menuService.getBaseMenuService();
    }
}
